class Db < ActiveRecord::Migration
  def self.up
      create_table :blogs do |blog|
        blog.column :name, :string
        blog.column :url,  :string, :null => false
        blog.column :click, :integer, :default => "0"
        blog.column :rank, :integer, :default => "9999999"
        blog.column :user_id, :integer
        blog.column :day, :integer, :default => 0
        blog.column :week, :integer, :default => 0   
        blog.column :month, :integer, :default => 0   
        blog.column :year, :integer, :default => 0 
      end
      create_table :tags do |tag|
        tag.column :name,  :string, :null => false
      end
      create_table :blogtags do |t|
        t.column :blog_id,  :integer, :null => false
        t.column :tag_id,  :integer, :null => false
        t.column :times,  :integer, :default => "1"
      end
      create_table :users do |table|
        table.column :openid_url, :string, :default => nil     
      end
      add_index :blogs, :url, :unique => true
      add_index :tags, :name, :unique => true
  end

  def self.down
    drop_table :blogs
    drop_table :tags
    drop_table :users
    drop_table :blogtags
  end
end
